home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Financial / Stopwatch2.3 / Source / Expense.m < prev    next >
Text File  |  1995-06-12  |  2KB  |  96 lines

  1. /*
  2.  * For legal stuff see the file COPYRIGHT
  3.  */
  4. #import <stdio.h>
  5. #import <stdlib.h>
  6. #import "Expense.h"
  7.  
  8. extern void freeAndCopy( char **ptr, const char *str );
  9. extern char *NXCopyStringBuffer(const char *buffer);
  10.  
  11. @implementation Expense
  12.  
  13. - init:(const char *)date
  14.        description:(const char *)desc
  15.        amount:(const float)amt
  16. {
  17.   [self setDateString:date];
  18.   [self setDescription:desc];
  19.   amount = amt;
  20.   return self;
  21. }
  22.  
  23. - (void) freeDesc
  24. {
  25.   if ( description ) {
  26.     free( description );
  27.     description = NULL;
  28.   }
  29. }
  30.  
  31. - free
  32. {
  33.   [self freeDesc];
  34.   return [super free];
  35. }
  36.  
  37. - setAmount:(float)value
  38. {
  39.   amount = value;
  40.   return self;
  41. }
  42.  
  43. - setDateString:(const char *)str
  44. {
  45.   freeAndCopy( &dateString, str );
  46.   return self;
  47. }
  48.  
  49. - setDescription:(const char *)desc
  50. {
  51.   [self freeDesc];
  52.   description = NXCopyStringBuffer(desc);
  53.   return self;
  54. }
  55.  
  56. - (const char *)dateString
  57. {
  58.   return dateString;
  59. }
  60.  
  61. - (const char *)description
  62. {
  63.   return description;
  64. }
  65.  
  66. - (float)amount
  67. {
  68.   return amount;
  69. }
  70.  
  71. /*
  72.  * For use in comparisons, convert date such as 11/21/93 to a
  73.  * single integer 932111. THIS SHOULD BE CACHED! (TBD)
  74.  */
  75. - (int)dateValue
  76. {
  77.   int day, month, year;
  78.  
  79.   sscanf( dateString, "%d/%d/%d", &month, &day, &year );
  80.   return ( year * 10000 + month * 100 + day );
  81. }
  82.  
  83. - read:(NXTypedStream *) stream
  84. {
  85.   NXReadTypes( stream, "**f", &description, &dateString, &amount );
  86.   return self;
  87. }
  88.  
  89. - write:(NXTypedStream *) stream
  90. {
  91.   NXWriteTypes( stream, "**f", &description, &dateString, &amount );
  92.   return self;
  93. }
  94.  
  95. @end
  96.